<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Notify extends Model
{
    use HasFactory;

    protected $fillable = ['project_id','days','type_id','user_id','module','send_date','status','remarks'];

    const POSTONLY = ['project_id','days','type_id','user_id','module','send_date','status','remarks'];

    const DAYS = [1=>'逾期一天',2=>'逾期二天',3=>'逾期三天',4=>'逾期四天',5=>'逾期五天',6=>'逾期六天',7=>'逾期七天',];

    protected $appends = [
        'days_text'
    ];
    
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getDaysTextAttribute()
    {
        return self::DAYS[$this->days];
    }

    public function safeType()
    {
        return $this->hasOne(SafeType::class,'id','type_id')->select('id','title');
    }

    public function QualityType()
    {
        return $this->hasOne(QualityType::class,'id','type_id')->select('id','title');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','name');
    }

}
